
import { defineStore } from 'pinia'
import userApi from '@/LC/api/user';
import socket from './socket.js';
import money from './money.js';
import ticker from './ticker.js';
import router from '/LC/router/index.js';
import pay from '../LC/api/pay.js';


const useUserStore = defineStore({
  id: 'user', // id必填，且需要唯一
  state: () => {
    return {
      name: '张三',
	  isLogin:'',
	  bank:[],
	  info:{
		 "nickname": "188****8888",
		         "username": "18888888888",
		         "totle_money": "0.00",
		         "balance_money": "0.00",
		         "frozen_money": "0.00",
		         "auth_status": 0,
		         "auth_trans": "未认证",
		         "init_trade_pwd": false,
		         "unread_msg": 0 
	  },
	  share_id:'',
	  token:'',
    }
  },
  unistorage: {
  	// 初始化恢复前触发
  	beforeRestore(ctx) {},
  	// 初始化恢复后触发
  
  },
   actions: {
     // 设置token
     setToken(token = '') {
       if (token === '') {
         this.isLogin = false;
         uni.removeStorageSync('token');
       } else {
         this.isLogin = true;
         uni.setStorageSync('token', token);
         this.loginAfter();
       }
       return this.isLogin;
     },
	 logout(){
		
		this.token='',
		this.isLogin=false,
		this.info={
			"nickname": "****",
			        "username": "****",
			        "totle_money": "0.00",
			        "balance_money": "0.00",
			        "frozen_money": "0.00",
			        "auth_status": 0,
			        "auth_trans": "未认证",
			        "init_trade_pwd": false,
			        "unread_msg": 0 
		}
		console.log(123123)
		uni.reLaunch({
			url:'/pages/auth/login'
		})
	 },
	 loginAfter(){
		// const moneyStore = money();
		// const socketStore = socket();
		
				
		// socketStore.socket()
		//  moneyStore.init()
	 	this.userinfo()
		this.banklist()
	 },
	async banklist(){
		 let res= await pay.account()
		 if(res.code===1){
		 	
		 	this.bank=res.data
		 }
	 },
	 async userinfo(){
		let res= await userApi.info()
		if(res.code===1){
			// res.data.totle_money=res.data.totle_money+''
			// res.data.balance_money=res.data.balance_money+''
			this.info=res.data
			
		}
		
	 }
    },
	
})
 export default useUserStore;